package io.renren.modules.company.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.utils.ConvertUtils;
import io.renren.modules.company.dao.CompanyDao;
import io.renren.modules.company.dto.CompanyDTO;
import io.renren.modules.company.entity.CompanyEntity;
import io.renren.modules.company.service.CompanyService;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 公司
 *
 * @author tree 
 * @since 1.0.0 2024-12-24
 */
@Service
public class CompanyServiceImpl extends CrudServiceImpl<CompanyDao, CompanyEntity, CompanyDTO> implements CompanyService {

    @Override
    public QueryWrapper<CompanyEntity> getWrapper(Map<String, Object> params){
        String companyname = (String)params.get("companyname");
        String platform = (String)params.get("platform");
        String country = (String)params.get("country");
        String continent = (String)params.get("continent");
        String salesperson= (String)params.get("salesperson");

        QueryWrapper<CompanyEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(companyname), "companyname", companyname);
        wrapper.eq(StrUtil.isNotBlank(platform), "platform", platform);
        wrapper.eq(StrUtil.isNotBlank(country), "country", country);
        wrapper.eq(StrUtil.isNotBlank(continent), "continent", continent);
        if(!"admin".equalsIgnoreCase(salesperson)){
            wrapper.eq(StrUtil.isNotBlank(salesperson), "salesperson", salesperson);
        }
        return wrapper;
    }


    @Override
    public CompanyDTO get(String companyname) {
        QueryWrapper<CompanyEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(companyname), "companyname", companyname);
        CompanyEntity companyEntity=baseDao.selectOne(wrapper);
        return ConvertUtils.sourceToTarget(companyEntity, CompanyDTO.class);
    }
}